<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<script type="text/javascript">
$(function(){
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$(".detail").colorbox({width:"80%", height:"70%", iframe:true});
});
</script>
<fieldset><legend>查询条件</legend>
<form action="" method="get">
<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>采购日期</th>
	<td>
		<input type="text" name="begin_purchase_time" class="datepicker" value="<?=isset($_GET['begin_purchase_time']) ? $_GET['begin_purchase_time'] : ''?>" /> to
		<input type="text" name="end_purchase_time" class="datepicker" value="<?=isset($_GET['end_purchase_time']) ? $_GET['end_purchase_time'] : ''?>" />
	</td>
</tr>
<tr>
	<th>采购单号</th>
	<td><input type="text" name="purchase_order_number" value="<?=isset($_GET['purchase_order_number']) ? $_GET['purchase_order_number'] : ''?>" /></td>
</tr>
<tr>
	<th>产品编号</th>
	<td><input type="text" name="product_basic_number" value="<?=isset($_GET['product_basic_number']) ? $_GET['product_basic_number'] : ''?>" /> 输入产品编号后六位例如：000001</td>
</tr>
<tr>
	<th>采购人员</th>
	<td>
		<select name="purchase_user_id">
		<option value="0">请选择...</option>
	  	<?foreach ($user as $u):?>
	  	<option value="<?=$u['id'];?>" <? if(isset($_GET['purchase_user_id']) && ($_GET['purchase_user_id']==$u['id'])):?>selected="selected"<? endif;?>><?=$u['name'];?></option>
	  	<? endforeach;?>
	  	</select>
	</td>
</tr>
<tr>
	<th>结款类型</th>
	<td>
		<select name="purchase_order_payment_type">
			<option value="">请选择..</option>
			<? foreach (Q::ini('custom_flag/purchase_order_payment_type') as $pt):?>
			<option value="<?=$pt['value']?>" <?if (isset($_GET['purchase_order_payment_type'])&&$_GET['purchase_order_payment_type']== $pt['value'])echo "selected='selected'" ?>><?=$pt['name']?></option>
			<? endforeach;?>
			</select>
	</td>
</tr>
<tr>
	<th>仓库</th>
	<td>
		<select name="warehouse_id">
			<option value="">请选择..</option>
			<?foreach ($warehouse as $w):?>
			<option value="<?=$w['id']?>" <?if (isset($_GET['warehouse_id'])&&$_GET['warehouse_id']==$w['id'])echo "selected='selected'"?>><?=$w['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>采购状态</th>
	<td>
		<?foreach (Q::ini('custom_flag/purchase_order_status') as $pos):?>
		<?if ($pos['value'] <= 3):?>
		<label><input type="checkbox" name="purchase_order_status[<?=$pos['value']?>]" value="<?=$pos['value']?>" <?if (isset($_GET['purchase_order_status']) && in_array($pos['value'], $_GET['purchase_order_status']))echo "checked='checked'"?> /> <?=$pos['name']?></label>
		<?endif;?>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<td></td>
	<td><input type="submit" class="button" value="查询" /></td>
</tr>
</table>
</form>
</fieldset>
<table class="list_table" width=100%>
	<tr>
		<th>采购单号</th>
		<th>所属仓库</th>
		<th>结款类型</th>
		<th>采购日期</th>
		<th>完成日期</th>
		<th>采购人</th>
		<th>预计总价</th>
		<th>实际总价</th>
		<th>状态</th>
		<th width="120">操作</th>
	</tr>
	<?foreach ($purchase_order as $po):?>
	<tr>
		<td><a class="detail" href="<?=url('Storage::Purchase/Detail', array('id'=>$po['id'], 'show_all' => 1))?>"><?=$po['number']?></a></td>
		<td><?=($po['warehouse_name'] == '广州仓') ? $po['warehouse_name'] : '<span class="red">' . $po['warehouse_name'] . '</span>'?></td>
		<td><?=Helper_BSS_Normal::getIniOne('purchase_order_payment_type','value',$po['payment_type'],'name')?></td>
		<td><?=$po['purchase_time']?></td>
		<td><?=$po['complete_time']?></td>
		<td><?=$po['purchase_user_name']?></td>
		<td><?=sprintf('%.2f', $po['budget_amount'])?></td>
		<td><?=sprintf('%.2f', $po['actual_amount'])?></td>
		<td><?=Helper_BSS_Normal::getIniOne('purchase_order_status', 'value', $po['status'], 'name')?></td>
		<td>
			<?if (($po['status'] == Q::ini('custom_flag/purchase_order_status/purchased/value')) && ($po['purchase_hold_flag'] == Q::ini('custom_flag/purchase_hold_flag/unhold/value'))):?>
			<a href="<?=url('Storage::Purchase/WarehouseAudit', array('id'=>$po['id'], Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>">确认</a>
			<?else:?>
			<font color="gray">确认</font>
			<?endif;?>
		</td>
	</tr>
	<?endforeach;?>
</table>
<?=$page?>
<?php $this->_endblock();?>